<?php
/*
 * 5/7/2011
 * controler xu ly phan movie cho admin
 * bao gom cac phan
 * - them 1 category moi
 * - them 1 episode moi
 * - them danh sach cac list film vao episode nay
 * luon kiem tra session xem co phai la admin hay ko moi cho su dung nhung chuc nang nay
 */
class Manage extends CI_Controller{
    function __construct() {
        parent::__construct();
    }

    function index(){
        if($this->session->userdata('logged_in') == TRUE && $this->session->userdata('title') == 'Administrator')
            $this->load->view('manage/index');
        else
            redirect('admincp/manage/login', 'location', 302);
    }

    function menu(){
        $this->load->view('manage/menu');
    }

    function head(){
        $this->load->view('manage/head');
    }

    function home(){
        $this->load->model('m_hitcounter');
        $agent = $this->m_hitcounter->userAgent();
        $data = array();
        $data['agent'] = $agent;
        $this->load->view('manage/home', $data);
    }

    function logIn(){
        $message = '';
        if($this->input->post('login-submit')){
            //check user pw
            $name = $this->input->post('name');
            $password = $this->input->post('password');
            $this->load->model('user/usermodel');
            $user = new UserModel();
            $user->_name = $name;
            $user->_password = md5($password);
            if($user->isAdmin()){
                $newdata = array(
                       'logged_in' => TRUE,
                       'title' => 'Administrator'
                );
                $this->session->set_userdata($newdata);
                redirect('admincp/manage', 'location', 302);
            }else{
                $data['message'] = 'Plz check your password';
                $this->load->view('manage/login', $data);
            }
        }
        else{
            $data['message'] = '';
            $this->load->view('manage/login', $data);
        }
    }

    function logOut(){
        $this->session->sess_destroy();
        redirect('admincp', 'location', 302);
    }

    function deleteCache(){
        $this->db->cache_delete_all();
    }
}
?>
